#include<stdio.h>
#include<stdlib.h>
int v[100];
int e[20][20];
int a;
int b;
int v1, v2;
int c;
int g = 0;
typedef struct {
	int edge1;
	int edge2;
	int weight;
}edg;
edg edge[20];
void Init() {
	a = 5;
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < a; j++) {
			e[i][j] = 1234567;
		}
	}
	e[0][1] = 1;
	e[0][3] = 5;
	e[0][2] = 7;
	e[0][4] = 2;
	e[1][2] = 15;
	e[2][3] = 77;
	e[3][4] = 24;
	e[4][1] = 67;
}
void Sort() {
	int t1;
	int t2;
	for (int i = 0; i < g; i++) {
		for (int j = 0; j < g; j++) {
			if (edge[i].weight <edge[j].weight) {
				t1 = edge[i].weight;
				t2 = edge[j].weight;
				edge[i].weight = t2;
				edge[j].weight = t1;
				t1 = edge[i].edge1;
				t2 = edge[j].edge1;
				edge[i].edge1 = t2;
				edge[j].edge1 = t1;
				t1 = edge[i].edge2;
				t2 = edge[j].edge2;
				edge[i].edge2 = t2;
				edge[j].edge2 = t1;
			}
		}
	}for (int i = 0; i < g; i++) {
		printf("(%d %d) %d\n", edge[i].edge1, edge[i].edge2, edge[i].weight);
	}printf("\n");
}
	int Find(int d, int* f) {
		if (f[d] == 0) return d;
		else return Find(f[d],f);
	}
void  Kruska() {
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < a; j++) {
			if (e[i][j] != 1234567) {
				edge[g].edge1 = i;
				edge[g].edge2 = j;
				edge[g].weight = e[i][j];
				g++;
			}
		}
	}
	Sort();
	int f[5] = {};
	int d, h;
	for (int i = 0; i < g; i++) {
		d = Find(edge[i].edge1, f);
		h = Find(edge[i].edge2, f);
		if (d != h) {
			printf("(%d %d) %d\n", edge[i].edge1, edge[i].edge2, edge[i].weight);
			f[d] = h;
		}
	}
}
int main() {
	Init();
	Kruska();
}
